package com.doushu.dispatch.mapper;

import com.doushu.dispatch.entity.KeywordZTC;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface KeywordZTCMapper {

    @Select({"SELECT MAX(datatime) FROM ds_keywordlist WHERE sid=#{sid}"})
    String findMaxDateTimeBySid(Long sid);

//    @Select({
//            "<script>"
//                    + "INSERT INTO ds_keywordlist(bidwordstr,bidwordid,transactionshippingtotal,cost,click,favtotal,linkurl,carttotal,iid,datatime,terminal,sid) VALUES"
//                    + "<foreach collection='list' item='keyword' separator=','>"
//                    + "(#{keyword.bidwordstr},#{keyword.bidwordid},#{keyword.transactionshippingtotal},#{keyword.cost},#{keyword.click},#{keyword.favtotal},#{keyword.linkurl},#{keyword.carttotal},#{keyword.iid},#{keyword.datatime},#{keyword.terminal},#{keyword.sid})"
//                    + "</foreach>"
//                    + "</script>"
//    })
//    Integer insertKeywords(List<KeywordZTC> keywords);

    @Insert("INSERT INTO ds_keywordlist(bidwordstr,bidwordid,transactionshippingtotal,cost,click,favtotal,linkurl,carttotal,iid,datatime,terminal,sid) VALUES (#{bidwordstr},#{bidwordid},#{transactionshippingtotal},#{cost},#{click},#{favtotal},#{linkurl},#{carttotal},#{iid},#{datatime},#{terminal},#{sid})")
    Integer insertKeyword(KeywordZTC item);

    @Select({"SELECT 1 FROM ds_keywordlist WHERE sid=#{sid} AND datatime=#{datatime} LIMIT 1"})
    Boolean existsBySidAndDatatime(@Param("sid")Long sid, @Param("datatime")String datatime);

    @Select({"SELECT iid FROM ds_keywordlist WHERE sid=#{sid} AND datatime=#{datatime}"})
    List<Long> findItemsBySidAndDatatime(@Param("sid")Long sid, @Param("datatime")String datatime);
}
